<?php
	include "../head.php";
?>
<head>
    <meta charset="utf-8">
    <title>YOHO!BUY 有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证</title>
		<link rel="stylesheet" type="text/css" href="list.css">
</head>
<body>
<?php
		//连接数据库
		$sex = array("1"=>"印花","2"=>"墨");
		include('../../../public/dbconfig.php');
		$link = mysqli_connect(HOST,USER,PASS,DBNAME);
		if(mysqli_connect_errno($link)){
			die('连接数据库失败');
		}
		mysqli_select_db($link,DBNAME);
		mysqli_set_charset($link,'utf8');
		//===========封装搜索条件================
		$wherelist = array();
		$urllsit = array();
		
		//var_dump($_GET);
		//var_dump(empty($_GET['price_1']));die;
		$wherelist = array();
		$where = "";
		$url = '';
		//var_dump();
		//2 接收搜索条件 
			if(!empty($_GET['goods'])){
				$wherelist[] = "goods='{$_GET['goods']}'";
				$urllist[] = "goods={$_GET['goods']}";
			}			
			if(!empty($_GET['picname'])){
				$wherelist[] =" picname like '%{$_GET['picname']}%'"; 
				$urllist[] = "picname={$_GET['picname']}";
			}	

	

		//3 判断搜索条件的有效性	
			if(count($wherelist)>0){
				$where = " where ".implode(" and ",$wherelist);
				$url = "&".implode("&",$urllist);
			}
		if(!empty($_GET['goods'])){
			$wherelist[] = "goods like '%{$_GET['goods']}%'";
			$urllist[] = "goods={$_GET['goods']}";
		}
		//var_dump($_GET['name']);die;
		//var_dump($_GET['pid']);
		if(!empty($_GET['price_1'])||$_GET['price_1']=='0'){
			$wherelist[] = "price between {$_GET['price_1']}";
			$urllist[] = "price_1={$_GET['price_1']}";
		}
		
		if(!empty($_GET['price_2'])){
			$wherelist[] = "{$_GET['price_2']}";
			$urllist[] = "price_2={$_GET['price_2']}";
		}
		//echo '<pre>';
		//print_r($wherelist);die;
		
		if(count($wherelist)>0){
			$where = " where ".implode(" and ",$wherelist);
			$url = "&".implode("&",$urllist);
			//echo $where;die;
		}

		//=========分页=============		
		$_GET['p'] = empty($_GET['p'])?0:$_GET['p']; //页码
		$pageSize = 9; //每页条数
		$maxPage = 0; //页数
		$maxRow = 0; //总条数
			
			//获得总条数 和总页数
		//2 一共有多少条 
		$sql = "select * from goods".$where;
		//echo $sql;die;
		$result = mysqli_query($link,$sql);
		$arr = mysqli_fetch_assoc($result);
		//print_r($arr);die;
		$maxRow = mysqli_num_rows($result);
		//echo $maxRow;
		$maxPage = ceil($maxRow/$pageSize);
		//echo $maxPage;die;
		//判断页码
		//4 判断页码 
		if($_GET['p']>$maxPage){
			$_GET['p'] = $maxPage;
		}
		if($_GET['p']<1){
			$_GET['p']=1;
		}	
		$limit = " limit ".($_GET['p']-1)*$pageSize.",".$pageSize;
			
?>	
	<div id="banner">
		<img src="banner.JPG">
	</div>
    <div id="xz">
        <font><a href="../YOHO PJ1/index.php">BOYS首页</a> > <a href="#">品牌一览</a> > <a href="#">5CM 5厘米</a></font>
    </div>
    
	<div id="tummy">
		<div id="small">
			<a href=""><img src="small.JPG"></a>
		</div>
	  
		<div id="right">
			<div id="bt001">
				<a href="#"><img src="2016-07-21_150611bbt111.jpg"></a>
			</div>
			<div id="choose">
						
				<div><font size="5"><b>已选条件:</b></font></div>
				<div id="sex">
				<form action = "list.php">
				 <span><b>风格：</b></span>
				 <select name="goods" style="margin:10px 0px">
					<option value="goods">-请选择-</option>
					<option value="<?php echo $_GET['goods']; ?>">-印花-</option>
					<option value="<?php echo $_GET['goods']; ?>">-墨-</option>
				 </select>
				 <input type="submit" value="搜索">
				</form>
				</div>
				<div id="price"><form action="list.php"><b size="3">价格:</b>&nbsp;&nbsp;&nbsp;¥0-300&nbsp;&nbsp;&nbsp;¥301-500&nbsp;&nbsp;&nbsp;¥501-700&nbsp;&nbsp;&nbsp;¥701-1000&nbsp;&nbsp;&nbsp;¥<input type="text" style="height:25;width:50;" name="price_1" value="<?php echo $_GET['price_1']; ?>">&nbsp;-&nbsp;<input type="text" style="height:25;width:50;" name="price_2" value="<?php echo $_GET['price_2']; ?>">&nbsp;&nbsp;&nbsp;<input type="submit" value="查询"></form></div>
				<div id="color"><b size="3">颜色:</b>&nbsp;&nbsp;&nbsp;<a href="#">黑色</a>&nbsp;&nbsp;&nbsp;<a href="#">白色</a>&nbsp;&nbsp;&nbsp;<a href="#">蓝色</a>&nbsp;&nbsp;&nbsp;<a href="#">灰色</a>&nbsp;&nbsp;&nbsp;<a href="#">红色</a></div>
				<div id="cc"><b size="3">高级选项:</b>&nbsp;&nbsp;&nbsp;风格<select><option>1</option><option>2</option><option>3</option></select>&nbsp;&nbsp;&nbsp;衣长<select><option>1</option><option>2</option><option>3</option></select>&nbsp;&nbsp;&nbsp;袖长<select><option>1</option><option>2</option><option>3</option></select>&nbsp;&nbsp;&nbsp;版型<select><option>1</option><option>2</option><option>3</option></select></div>
			</div>
			<div id="right1">
				默认 &nbsp;&nbsp;  <form action = "list.php">选择<select name="id"><option value="11">热销</option><option value="12">新品</option><option value="27">推荐</option></select>&nbsp;<input type="submit" value="搜索">&nbsp;&nbsp;&nbsp;<input type="text" name="search" value="<?php echo $_GET['goods']; ?>" style="width:120px" placeholder="请输入商品名称">&nbsp;<input type="submit" value="搜索"></form>
			</div>
			<div id="shangpin">
		<?php	
				//1 导入配置文件 
				include("../../../public/dbconfig.php");
				//2 连接数据库
				$link = @mysqli_connect(HOST,USER,PASS) or die("数据库连接失败");
				//3 选择数据库 设置字符集
				mysqli_set_charset($link,"utf8");
				mysqli_select_db($link,DBNAME);
				//where 使用昨天的封装搜索条件
				//4 设置数组来接收搜索的条件 
				$wherelist = array();

				//5 判断get方式传值 搜索条件是否存在
				if(!empty($_GET['typeid'])){
					$wherelist[] = "typeid in(select id from type where path like '%,{$_GET['typeid']},%')";
				}
				
				//6 查看搜索条件数组是否有值 
				if(count($wherelist)>0){
					$where  = " where ".implode(" and ",$wherelist);
				}
				//var_dump($where);die;
				//7 拼接sql/语句
				$sql = "select * from goods ".$where;
				//echo $sql;die;
				$result = mysqli_query($link,$sql);
				// echo $result;die;
				while($row = mysqli_fetch_assoc($result)){
$str = <<<aa
		
	<div class="item">
				<div class="item_cont">
					<div id="sp1">
						<a href="../xiangqing/xiangqing.php?id={$row['id']}"><img src="../../../public/uploads/{$row['picname']}" alt=""></a>
						<p><a href="#">5CM {$row['goods']}</a></p>
						<p>5CM</p>
						<p class="money">¥{$row['price']}</p>
					</div>
					
				</div>
			</div>

aa;

	echo $str;
				}

		?>
					
				
				<div id="total">
					<!--<font>总计商品xxx件&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;第<input type="text" style="width:20px">页</font>-->
				<!---------------分页-------------------->

		<tr>
			<td align="left" valign="top" class="fenye"><?php echo $maxRow." 条数据 ".$_GET['p']."/".$maxPage." 页";?>&nbsp;&nbsp;<a href="list.php?p=1<?php echo $url;?>" target="mainFrame" onFocus="this.blur()">首页</a>&nbsp;&nbsp;<a href="list.php?p=<?php echo ($_GET['p']-1).$url;?>" target="mainFrame" onFocus="this.blur()">上一页</a>&nbsp;&nbsp;<a href="list.php?p=<?php echo ($_GET['p']+1).$url;?>" target="mainFrame" onFocus="this.blur()">下一页</a>&nbsp;&nbsp;<a href="list.php?p=<?php echo $maxPage.$url;?>" target="mainFrame" onFocus="this.blur()">尾页</a></td>
		</tr>
				<!----------------分页----------------------->		
				</div>
			</div>
			<div id="recent">
				<a href="#"><img src="recentfwhio32h1r119.JPG"></a>
			</div>
		</div>
		
		<div id="left">
			<div id="left1">
				<img src="1.JPG">
			</div>
			<div id="left2">
				<img src="2.JPG">
			</div>
			<div id="left3">
				<img src="3.JPG">
			</div>
			<div id="left4">
				<img src="023ca4ae39cbd22458af4427c11af49fe7.gif">
			</div>
			<div id="left5">
				<img src="5.JPG">
			</div>
		</div>
		
		
	</div>	
		
		
	<div id="foot">
		<img src="hkinczio.jpg">
	</div>
	
</body>
